<!DOCTYPE html>
<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
        <script src="js/jquery.min.js"></script>
		<script src='js/jquery-ui-1.11.3.custom/jquery-ui.min.js'></script>
        <script>
            $(document).ready(function(){
			
				$('#wobj').autocomplete({
					source: ['wobj0','wobjHor_0','wobjHor_17','wobjHor_12','wTrnTbl','wTblCtr','wTblA','wSmallTbl']
				});
				$('#tool').autocomplete({
					source: ['tool0','t9MB_45','t9MB_45_4','t9MB_90_4','t9MB_90_4o5','t3mb12_45_4','t3mb12_90_4']
				});

            	//auto fill today's date in date field
            	$('#date').val(new Date().toLocaleDateString())
            	
				//attach functions to buttons
            	$('#addmcoptionbtn').click(function(){addmcoption();});
            	$('#removemcoptionbtn').click(function(){removeItem('.mct');});
            	$('#addnumoptionbtn').click(function(){addnumoption();});
            	$('#removenumoptionbtn').click(function(){removeItem('.nct');});
            	$('#addspeedbtn').click(function(){addspeed()});
            	$('#removespeedbtn').click(function(){removeItem('.sct')});
            	$('#addrobtargetbtn').click(function(){addrobtarget()});
            	$('#removerobtargetbtn').click(function(){removeItem('.rct')});
            	$('#addmovebtn').click(function(){addmove()});
            	$('#addpostmovebtn').click(function(){addpostmove()});
            	$('#addpremovebtn').click(function(){addpremove()});
            	$('#removemovebtn').click(function(){removeItemFrom('.mvc:last','#moves')});
            	$('#removepostmovebtn').click(function(){removeItemFrom('.mvc:first','#postmoves')});
            	$('#removepremovebtn').click(function(){removeItemFrom('.mvc:last','#premoves')});
            	$('#importrtbtn').click(function(){importrt()});
				$('#showimportrt').click(function(){
					$('#importrtc').slideDown();
				});
				$('#mrpmcheck').change(function(){
            		var b=$(this).prop('checked');
            		$('#rpm1').attr('placeholder',b?'RPM (bond)':'RPM');
            		$('#rpm2').css('display',b?'inline':'none');
            		togglecoatoption();
            	});
            	$('#mspeedcheck').change(function(){togglespeeds()});
				$('#mstandoff').change(function(){
					if($(this).prop('checked')){
						$('#standoffs').slideDown();
						$('#relz').val('standoff{ncoat}');
					}
					else{
						$('#standoffs').slideUp();
						$('#relz').val(0);
					}
					togglecoatoption();
				});
            	$('#genp').click(function(){gentext()});
            	
				//add first speed
            	addspeed().addClass('locked');
				
				//add phome and pappr
				var phome=addrobtarget().addClass('locked');
				phome.find('.rtname:first').val('pHOME').attr('disabled','disabled').change();
				var pappr=addrobtarget().addClass('locked');
				pappr.find('.rtname:first').val('pAPPR').attr('disabled','disabled');
				addrobtarget();
				addrobtarget();
				var movetemp=addmove();
				movetemp.find('.mvp').val('p10');
				movetemp.find('.mvs').val('v200');
				movetemp.find('.mvt').val('MoveJ');
				movetemp=addmove();
				movetemp.find('.mvp').val('p20');
				movetemp.find('.mvs').val('vcoat1');
				movetemp=addmove();
				movetemp.find('.mvp').val('p10');
				movetemp.find('.mvs').val('vcoat1');
				movetemp=addpremove();
				movetemp.find('.mvp').val('pAPPR');
				movetemp.find('.mvs').val('v200');
				movetemp=addpostmove();
				movetemp.find('.mvp').val('pHOME');
				movetemp.find('.mvs').val('v200');
				movetemp=addpostmove();
				movetemp.find('.mvp').val('pAPPR');
				movetemp.find('.mvs').val('v200');
				
				//add set cycles option
            	addnumoption().addClass('locked');
            	$('.nct:first').find('.numoname').val('cycles');
            	$('.nct:first').find('.numoprompt').val('Enter number of cycles');
            	$('.nct:first').find('input').attr("disabled","true");
            	$('.nct:first').find('.numdec').val(0);
				
				$([['Relative to Tool offsets','rel'],['Relative to Tool Angle Offsets','rang'],['World Coordinate Offsets','off']]).each(function(){
					$('#roffs').append(
						$('<span>').attr({'class':'subsechead'}).text(this[0])
					);
					var t=this[1];
					$(['x','y','z']).each(function(){
						$('#roffs').append(
							$('<div>').css({'display':'inline-block'}).append(
								$('<label>').text(t+this).attr({'for':t+this}), '</br>',
								$('<input>').attr({'type':'text','size':'15','id':t+this,'value':0}).change(function(){
									$(this).val($(this).val().trim());
									if($(this).val()=='')
										$(this).val(0);
								})
							)
						);
					});
				});
				
            	//put cursor in first field
            	$('input:first').focus(); 
            }); //document.ready
            
            function addmcoption(){
            	var mct=$('<div>').addClass("mct oct")
            		.append($('<input>').attr({"type":"text","size":"12","class":"mconame","placeholder":"option name"}),
						$('<input>').attr({"type":"text","size":"30","class":"mcoprompt","placeholder":"User prompt"}),
						$('</br>'));
            	for(var i=1;i<=5;i++){
            		mct.append($('<input>').attr({"type":"text","size":"8","class":"fk","placeholder":"option "+i}));
            	}
            	$('#mcops').append(mct);
            	return mct.hide(0,function(){$(this).slideDown('fast');});
            } //addmcoption
            
            function togglespeeds(){
                var b=$('#mspeedcheck').prop('checked');
                $('.sp1').attr('placeholder',b?'speed (bond)':'speed');
                $('.sp2').css('display',b?'inline':'none');
                togglecoatoption();
            }
            
            function addspeed(){
				var nid="vcoat"+($('.sct').length+1);
                var st=$(document.createElement('div')).addClass("sct oct").attr('id','vcoat'+($('.sct').length+1))
                    .append($(document.createElement('input')).attr({"type":"text","size":"10","class":"spname","placeholder":"speed name","value":nid})
						.change(function(){
							$('.'+nid).text($(this).val());
							$('.'+nid).val($(this).val());
						}),
                    $('<input>').attr({"type":"text","size":"10","class":"sp1","placeholder":"speed"}),
                    $('<input>').attr({"type":"text","size":"10","class":"sp2","placeholder":"speed (top)"}));
                $('#speeds').append(st);
                togglespeeds();
				$('.mvs').each(function(){
					$(this).append($(document.createElement('option')).attr({'class':st.attr('id'),'value':st.attr('id')}).text(st.find('.spname').val()));
				});
                return st.hide(0,function(){$(this).slideDown('fast');});
            } //addspeed
			
			function addrobtarget(){
				var nid="p"+10*($('.rct').length-1);
                var rt= $(document.createElement('div')).addClass("rct oct").attr({"id":nid})
                    .append($(document.createElement('input')).attr({"type":"text","size":"10","class":"rtname","placeholder":"robtargets name","value":nid})
						.change(function(){
							$('.'+nid).text($(this).val());
							$('.'+nid).val($(this).val());
						}))
                    .append($(document.createElement('input')).attr({"type":"text","size":"80","class":"rtv","placeholder":"robtarget data","value":"[[0,0,0],[1,0,0,0],[0,0,0,0],[9E+09,9E+09,9E+09,9E+09,9E+09,9E+09]]"})).appendTo('#robtargets');
				$('.mvp,.movecp').append($(document.createElement('option')).attr({'class':rt.attr('id'),'value':rt.attr('id')}).text(rt.find('.rtname').val()));
				return rt.hide(0,function(){$(this).slideDown('fast');});
			} //addrobtarget
			
			
			function addmove(){
				var mvs=$(document.createElement('select')).attr({'class':'mvs'});
				$(['v10','v20','v100','v200']).each(function(){
					mvs.append($('<option>').attr({'class':this+' builtinspeed','val':this}).text(this));
				});
				$('.sct').each(function(){
					mvs.append($(document.createElement('option')).attr({'class':$(this).attr('id'),'value':$(this).attr('id')}).text($(this).find('.spname').val()));
				});
				var mvp=$(document.createElement('select')).attr({'class':'mvp'});
				var movecp=$(document.createElement('select')).attr({'class':'movecp',}).hide();
				$('.rct').each(function(){
					mvp.append($(document.createElement('option')).attr({'class':$(this).attr('id'),'value':$(this).find('.rtname').val()}).text($(this).find('.rtname').val()));
					movecp.append($(document.createElement('option')).attr({'class':$(this).attr('id'),'value':$(this).find('.rtname').val()}).text($(this).find('.rtname').val()));
				});		
				var mvt=$('<select>').attr({'class':'mvt'}).change(function(){movecp.css('display',$(this).val()=='MoveC'?'inline':'none')});
				$(['MoveL','MoveJ','MoveC']).each(function(){mvt.append($('<option>').val(this).text(this));});
				var mvz=$('<select>').attr({'class':'mvz'});
				$(['fine','z1','z5','z10','z20','z50']).each(function(){mvz.append($('<option>').val(this).text(this));});
				var move=$(document.createElement('div')).addClass('mvc oct')
					.append(mvt,mvp,movecp,' speed ',mvs,' zone ',mvz,$('<button>').html('&darr;').click(function(){
						$(move).next().after($(move).hide().slideDown());
					}))
					.appendTo('#moves').hide(0,function(){$(this).slideDown('fast');});
				return move;
			}
			
			function addpostmove(){
				var v=addmove().prependTo('#postmoves');
				v.find($('.mvz')).val('z20');
				v.find($('.mvt')).val('MoveJ');
				return v;
			}
			function addpremove(){
				return addpostmove().appendTo('#premoves');
			}
            
            function togglecoatoption(){
            	if(!$('#coatoption').length && ($('#mrpmcheck').prop('checked') || $('#mspeedcheck').prop('checked')||$('#mstandoff').prop('checked'))){
            		var coatoption=addmcoption().attr('id','coatoption').addClass('locked');
            		$('#mcops').prepend(coatoption);
            		coatoption.find('.mconame').val('coat').attr('disabled','disabled');
            		coatoption.find('.mcoprompt').val('Select coat type');
            		$(coatoption.find('.fk')[0]).val('BOND');
            		$(coatoption.find('.fk')[1]).val('TOP');
            		$(coatoption.find('.fk')[2]).attr('disabled','disabled')
            		$(coatoption.find('.fk')[3]).attr('disabled','disabled')
            		$(coatoption.find('.fk')[4]).attr('disabled','disabled')
            	} else if(!($('#mrpmcheck').prop('checked') || $('#mspeedcheck').prop('checked')||$('#mstandoff').prop('checked'))){
            		$('#coatoption').slideUp('fast',function(){$(this).remove();});
            	}
            }
            
            function addnumoption(){
            	var nct=$(document.createElement('div')).addClass('nct oct').append(
            		$(document.createElement('input')).attr({"type":"text","size":"10","class":"numoname","placeholder":"option name"}),
            		$(document.createElement('input')).attr({"type":"text","size":"29","class":"numoprompt","placeholder":"User prompt"}),
            		'</br>',
            		$(document.createElement('input')).attr({"type":"text","size":"5","class":"numunit","placeholder":"unit"}),
            		$(document.createElement('input')).attr({"type":"text","size":"5","class":"numdv","placeholder":"default val"}),
            		$(document.createElement('input')).attr({"type":"text","size":"5","class":"nummin","placeholder":"min"}),
            		$(document.createElement('input')).attr({"type":"text","size":"5","class":"nummax","placeholder":"max"}),
            		$(document.createElement('input')).attr({"type":"text","size":"5","class":"numdec","placeholder":"decimals"}));
            	$('#numops').append(nct);
				return nct.hide(0,function(){$(this).slideDown('fast');});
            } //addnumoption
            
            function removemcoption(){
            	if (!$('.mct').last().is('#coatoption')) 
            		$('.mct').last().remove();
            } //removemcoption
			
			function removeItem(s){
				if(!$(s).last().hasClass('locked')){
					$('.'+$(s).last().attr('id')).remove();
					$(s).last().slideUp('fast',function(){$(this).remove();})
				}
			}
			
			function removeItemFrom(s, f){
				if(!$(f).find(s).last().hasClass('locked')){
					$(f).find(s).last(s).slideUp('fast',function(){$(this).remove();})

				}
			}
			
			function importrt(){
				$('#importrtc').slideUp();
				$($('#rtimport').val().trim().split('\n')).each(function(){
					var b=true;
					var s=this.trim();
					var rtn=s.split('robtarget')[1].split(':')[0].trim();
					$('.rct').each(function(){
						if(rtn.toUpperCase()==$(this).find('.rtname').val().trim().toUpperCase()){
							$(this).find('.rtv').val(s.split('=')[1].trim().replace(';',''));
							b=false;
						}
					});
					if(b){
						var nrt=addrobtarget();
						nrt.find('.rtv').val(s.split('=')[1].trim().replace(';',''))
						nrt.find('.rtname').val(rtn).change();
					}
					
				});
			}
			
            function gentext(){
				var progwindow = window.open("", "");
				progwindow.document.write('<div style="font-family:monospace" id="demo"></div>');
				var indent=0;
            	var rapiddata=['VAR num fk;', 'CONST num rev:='+$('#rev').val()+';'];
				var rapidprocs=[];
				var initialsettings=[];
				var settingsdisplay=[];
				var tool=$('#tool').val();
				var wobj=$('#wobj').val();
				
				function makeRapidData(cv,t,n,v){
					var s=cv+' '+t+' '+n;
					if(v.length==1)
						s+=':='+v[0];
					if(v.length>1){
						s+='{'+v.length+'}:=[';
						for(var i=0;i<v.length;i++){
							s+=v[i]+((i<v.length-1)?',':']');
						}
					}
					rapiddata.push(s+';');
				}
				
				//write output to destination window
				function write(s){ progwindow.document.getElementById("demo").innerHTML+=s;}
				
				//print lines in bulk
				function printlines(ls){for(var i=0;i<ls.length;i++) println(ls[i]);}

				//print rapid lines w/ indentation and formatting
				function println(s){
					s=s.trim(); //remove excess spaces
					if (s.length==0) return;
					//un-indent for ENDPROC etc...,CASE
					if(s.indexOf("CASE")==0 || s.indexOf("END")==0)
						indent--;
						
					//print 2 spaces for each indent level
					for(var i=0; i<indent*2&&s.charAt(0)!='!'; i++)
						write("&nbsp");
						
					//print the line
					write(s+"</br>");
					
					//indent after MODULE,PROC,FUNC,FOR,IF(THEN),TEST,CASE
					if(s.indexOf("PROC")==0 || s.indexOf("FOR")==0  
							|| s.indexOf("TEST")==0 || s.indexOf("CASE")==0
							|| (s.indexOf("IF")==0 && s.indexOf("THEN")!=-1)
							|| s.indexOf("MODULE")==0 || s.indexOf("FUNC")==0)
						indent++;
						
					//add extra blank line after end of PROC
					if(s=="ENDPROC"||s=="ENDFUNC") 
						write("</br>");
				}
				
				//create header proc
				rapidprocs[rapidprocs.length]=[
					'PROC header()',
					'TPErase;',
					'TPWrite "CUSTOMER:    '+$('#cust').val()+'";',
					'TPWrite "PART NUMBER: '+$('#pn').val()+'";',
					'TPWrite "DESCRIPTION: '+$('#pdesc').val()+'";',
					'ENDPROC'
				];
				
				$('.rct').each(function(){
					makeRapidData('CONST','robtarget',$(this).find('.rtname').val(),[$(this).find('.rtv').val()]);
				});
				
				//get speeds
				$('.sct').each(function(){
					if($('#mspeedcheck').prop('checked')){
						makeRapidData('CONST','speeddata',$(this).find('.spname').val(),['['+($(this).find('.sp1').val()*$('#speedunit').val()).toFixed(2)+',500,5000,1000]','['+($(this).find('.sp2').val()*$('#speedunit').val()).toFixed(2)+',500,5000,1000]']);
					} else {
						makeRapidData('CONST','speeddata',$(this).find('.spname').val(),['['+($(this).find('.sp1').val()*$('#speedunit').val()).toFixed(2)+',500,5000,1000]']);
					}
				});
				
				//num options
				$('.nct').each(function(){
					var numoname=$(this).find('.numoname:first').val();
					var dv=$(this).find('.numdv:first').val();
					var max=$(this).find('.nummax:first').val();
					var min=$(this).find('.nummin:first').val();
					var dec=$(this).find('.numdec:first').val();
					if(dec=='') dec=2;
					var unit=$(this).find('.numunit:first').val();
					if(dv=='') {
						makeRapidData('VAR','num',numoname,[]);
						initialsettings[initialsettings.length]='set'+numoname+';';
					} else {
						makeRapidData('VAR','num',numoname,[dv]);
					}
					if(max!='')
						makeRapidData('CONST','num','max'+numoname,[max]);
					if(min!='')
						makeRapidData('CONST','num','min'+numoname,[min]);
					var sd='TPWrite "Current '+numoname+' = "+NumToStr('+numoname+','+dec+')'+(unit==''?'':('+" '+unit+'"'))+';';
					settingsdisplay[settingsdisplay.length]=sd;
					rapidprocs[rapidprocs.length]=[
						'PROC set'+numoname+'()',
						'TPErase;',
						dv==''?'':sd,
						max==''?'':'TPWrite "max "+NumToStr(max'+numoname+','+dec+');',					
						min==''?'':'TPWrite "min "+NumToStr(min'+numoname+','+dec+');',
						'TPReadNum '+numoname+',"'+$(this).find('.numoprompt:first').val()+'";',
						max==''?'':'IF '+numoname+'&gt;max'+numoname+' '+numoname+':=max'+numoname+';',
						min==''?'':'IF '+numoname+'&lt;min'+numoname+' '+numoname+':=min'+numoname+';',
						'ENDPROC'
					];
				});
				
				//multiple choice options
            	$('.mct').each(function(){
            		var fks=[];
            		$(this).find('.fk').each(function(){
            			if($(this).val().trim()!='')
            				fks[fks.length]='"'+$(this).val()+'"';
            		});
            		if(fks.length>0){
            			var mconame=$(this).find('.mconame').val().trim();
						makeRapidData('CONST','string','s'+mconame,fks);
						makeRapidData('VAR','num','n'+mconame,[]);
						initialsettings[initialsettings.length]='set'+mconame+';';
						settingsdisplay[settingsdisplay.length]='TPWrite "'+mconame+' = "+s'+mconame+'{n'+mconame+'};';
						var t='';
						for(var i=1;i<=5;i++)
							t+=(i<=fks.length?('s'+mconame+'{'+i+'}'):'""')+(i==5?'':',');
						rapidprocs[rapidprocs.length]=[
							'PROC set'+mconame+'()',
							'TPErase;',
							'TPReadFK n'+mconame+',"'+$(this).find('.mcoprompt').val()+'",'+t+';',
							'ENDPROC'
						];
            		}
            	});
				
				//get rpm settings
				var srpm=$('#rpm1').val();;
				if($('#mrpmcheck').prop('checked')){
					makeRapidData('CONST','string','srpm',['"'+$('#rpm1').val()+'"','"'+$('#rpm2').val()+'"'])
					srpm='"+srpm{ncoat}+"';
				} 
				rapidprocs[rapidprocs.length]=[
					'PROC confirm()',
					'TPReadFK fk,"Set turntable to '+srpm+' RPM, then press START to begin coating","","","START","","cancel";',
					'IF fk=3 rcoat;',
					'ENDPROC'
				];
				
				//get standoff variable if necessary
				if($('#mstandoff').prop('checked')){
					var s1=25.4*($('#pointer').val()-$('#standoff1').val());
					var s2=25.4*($('#pointer').val()-$('#standoff2').val());
					makeRapidData('CONST','num','standoff',[s1,s2]);
				}
								
				var introproc=[
					'PROC intro()',
					'header;',
					'TPWrite "Bldg '+$('#bldg').val()+' Booth '+$('#booth').val()+'";',
					'TPReadFK fk,"PROCEED WITH PROGRAM?","GO HOME","SKIP","","","EXIT";',
					'IF fk=5 EXIT;',
					'IF fk=1 MoveJ\\Conc,pHOME,v300,fine,'+tool+'\\WObj:='+wobj+';',
					'TPErase;',
					$('#addlsetup').val()==''?'':('TPWrite "'+$('#addlsetup').val()+'";'),
					'TPReadFK fk,"'+$('#tblsetup').val()+'","","","OK","","";',
					'TPErase;'
				].concat(initialsettings).concat(['ENDPROC']);//.push('ENDPROC');
				rapidprocs[rapidprocs.length]=introproc;
				
				var mainmenubuttons=['"START"'];
				var mainmenuprocs=['confirm;'];
				
				$('.mct,.nct').find('.numoname,.mconame').each(function(i){
					mainmenubuttons[mainmenubuttons.length]='"'+$(this).val()+'"';
					mainmenuprocs[mainmenuprocs.length]='set'+$(this).val()+';';
				});
				mainmenubuttons[mainmenubuttons.length]='"EXIT"';
				mainmenuprocs[mainmenuprocs.length]='EXIT;';
				
				//rcoat.................
				
				var rcoat=[
					'PROC rcoat()'
				];
				
				$('#premoves').find('.mvc').each(function(){
					rcoat[rcoat.length]=$(this).find('.mvt').val()+' '+$(this).find('.mvp').val()+','
						+($(this).find('.mvt').val()=='MoveC'?$(this).find('.movecp').val()+',':'')
						+$(this).find('.mvs').val()
						+ (($('#mspeedcheck').prop('checked')&&!$(this).find('.'+$(this).find('.mvs').val()).hasClass('builtinspeed'))?'{ncoat}':'') +','
						+$(this).find('.mvz').val()+','+tool+'\\WObj:='+wobj+';'
				});
				rcoat=rcoat.concat(['FOR c FROM 1 TO cycles DO',
					'TPErase;',
					'TPWrite "Running cycle "+NumToStr(c,0)+" of "+NumToStr(cycles,0);'
				]);
				
				var rel=false, offs=false, r='',ra='',o='',prepoint='',postpoint='';
				$(['x','y','z']).each(function(){
					if($('#rel'+this).val()!=0 || $('#rang'+this).val()!=0){
						rel=true;
					}
					if($('#off'+this).val()!=0){
						offs=true;
					}
					r+=','+$('#rel'+this).val();
					o+=','+$('#off'+this).val();
					if($('#rang'+this).val()!=0)
						ra+='\\R'+this+':='+$('#rang'+this).val();
				});
				if(rel){
					prepoint='RelTool('+prepoint;
					postpoint+=r+ra+')';
				}
				if(offs){
					prepoint='Offs('+prepoint;
					postpoint+=o+')';
				}
				
				$('#moves').find('.mvc').each(function(){
					var p1=prepoint+$(this).find('.mvp').val()+postpoint;
					var p2=prepoint+$(this).find('.movecp').val()+postpoint;
					rcoat[rcoat.length]=$(this).find('.mvt').val()+' '+p1+','
						+($(this).find('.mvt').val()=='MoveC'?p2+',':'')
						+$(this).find('.mvs').val()
						+ (($('#mspeedcheck').prop('checked')&&!$(this).find('.'+$(this).find('.mvs').val()).hasClass('builtinspeed'))?'{ncoat}':'') +','
						+$(this).find('.mvz').val()+','+tool+'\\WObj:='+wobj+';'
				});
				rcoat[rcoat.length]='ENDFOR';
				$('#postmoves').find('.mvc').each(function(){
					rcoat[rcoat.length]=$(this).find('.mvt').val()+'\\Conc,'+$(this).find('.mvp').val()+','
						+($(this).find('.mvt').val()=='MoveC'?$(this).find('.movecp').val()+',':'')
						+$(this).find('.mvs').val()
						+ (($('#mspeedcheck').prop('checked')&&!$(this).find('.'+$(this).find('.mvs').val()).hasClass('builtinspeed'))?'{ncoat}':'') +','
						+$(this).find('.mvz').val()+','+tool+'\\WObj:='+wobj+';'
				});
				rcoat.push('ENDPROC');
				rapidprocs.push(rcoat);
				
				function genmenu(p,b,pr){
					var s=[];
					s[s.length]=('TPReadFK fk,"'+p+'",');
					s[s.length]='TEST fk';
					for(var i=0;i<4;i++){
						if (i<b.length){
							s[0]+=b[i]+',';
							s[s.length]='CASE '+(i+1)+':';
							s[s.length]=pr[i];
						}
						else
							s[0]+='"",';
					}
					if(b.length>5){
						s[0]+='"MORE";';
						var bn=["BACK"];
						var pn=["TPErase;"];
						for(var i=4;i<b.length;i++){
							bn[bn.length]=b[i];
							pn[pn.length]=pr[i];
						}
						s[s.length]='CASE 5:';
						for(var i=0;i<genmenu("",bn,pn).length;i++)
							s[s.length]=genmenu("",bn,pn)[i];
					}
					else if(b.length==5){
						s[0]+=b[4]+';';
						s[s.length]='CASE 5:';
						s[s.length]=pr[4];
					} else {
						s[0]+='"";';
					}
					s[s.length]='ENDTEST';
					return s;
				}
				
				rapidprocs.push(['PROC main()','intro;','MAINMENU:','header;']
					.concat(settingsdisplay)
					.concat(genmenu("START coating or change settings?",mainmenubuttons,mainmenuprocs))
					.concat(['GOTO MAINMENU;','ENDPROC']));
				
				//special RAPID file header
				println("%%%");
				indent++;
				println("VERSION:1");
				println("LANGUAGE:ENGLISH");
				indent--;
				println("%%%");
				write("</br>");
				
				//start MODULE
				println("MODULE "+$('#prgname').val());
				
				//MSC program/part info
				printlines([
					"!PROGRAM NAME: "+$('#prgname').val(),
					"!CUSTOMER: "+$('#cust').val(),
					"!PART NUMBER: "+$('#pn').val(),
					"!DESCRIPTION: "+$('#pdesc').val(),
					"!AUTHOR: "+$('#author').val(),
					"!DATE: "+$('#date').val(),
					"!LOCATION: Bldg "+$('#bldg').val()+" Booth "+$('#booth').val(),
					"!REVISION HISTORY",
				'']);
				write("</br>");
				
				printlines(rapiddata);
				write("</br>");
				
				for (var i=0;i<rapidprocs.length;i++)
					printlines(rapidprocs[i]);
					
				println('ENDMODULE');
				
            }//gentext

        </script>
		<link rel="stylesheet" type="text/css" href="js/jquery-ui-1.11.3.custom/jquery-ui.min.css">
        <style>
			body {
				font-family:monospace;
			}
			input {
				font-family:monospace;
				margin: 2px;
			}
			button {
				margin:2px;
			}
            .oct {
            	margin: 2px;
				padding: 2px;
				width:auto;
				display:block;
            }
			.oct:hover {
				background-color:lightgreen;
			}
			.locked {
			}
			.req {
			}
			#mcops,#numops,#speeds,#robtargets,#moves,#premoves,#postmoves{
				display:inline-block;
				background-color:lightblue;
			}
			div.sec{
				width:auto;
				margin:5px;
				padding:5px;
				background-color:lightgrey;
				display:inline-block
			}
			div.smallinput label { 
			  display: inline-block; 
			  padding-right: .25em; 
			  width: 15em; 
			  text-align: right; 
			  clear:left;
			} 
			div.largeinput label {
			} 
			div.largeinput input {
			}

			div.smallinput input { 
			  margin: 1px;
			  display: inline-block;
			} 

			.sechead {
				display:block;
				padding: 5px;
				font-size:125%;
				font-weight:bold;
				background-color:yellowgreen;
			}

			.subsechead {
				display:block;
				font-size:110%;
				padding:2px;
			}

			input:active, 
			input:focus, 
			input:hover, 
			textarea:active, 
			textarea:focus, 
			textarea:hover,
			select:active,
			select:focus,
			select:hover { 
			  background-color: yellow;
			  border-color:green;
			} 
        </style>
    </head>
    <body>
		<div class='sec'>
			<span class='sechead'>Program/Part Info</span>
			
			<div class='smallinput'>

				<label for='author'>Author: </label>
				<input type="text" id="author" placeholder="F. LASTNAME">
				</br>
				<label for='date'>Date: </label>
				<input type="text" id="date" placeholder="">
				</br>
				<label for='bldg'>Bldg: </label>
				<input name="bldg" type="text" size=2 id="bldg" placeholder="#">
				</br>
				<label for='booth'>Booth: </label>
				<input name="booth" type="text" size=2 id="booth" placeholder="#">
				</br>
				<label for='prgname'>Program name:</label>
				<input size=5 type="text" class='req' id="prgname" value='P' placeholder="P####">
				</br>
				<label for='rev'>Revision Number:</label>
				<input size=5 type="text" class='req' id="rev" placeholder="#.#" value="1.0">
				</br>
				<label for='cust'>Customer</label>
				<input type="text" id="cust" placeholder="customer">
				</br>
				<label for='pn'>Part No.</label>
				<input type="text" id="pn" placeholder="P/N">
				</br>
				<label for='pdesc'>Part Description:</label>
				<input type="text" id="pdesc" placeholder="description">		
				</br>
				<label for='tool'>Tool:</label>
				<input type="text" id="tool" placeholder="tool" value='tool0'>		
				</br>
				<label for='wobj'>Wobj:</label>
				<input type="text" id="wobj" placeholder="wobj" value='wobj0'>
			</div>
		</div>
		</br>
		
		<div class='sec'>
			<span class='sechead'>Job Setup Info</span>
			
			<div class=largeinput'>
				<label for='tblsetup'>Turntable Setup</label></br>
				<input type="text" size=50 id="tblsetup" value="TURNTABLE ANGLE:0, DISTANCE:0" placeholder="turntable setup?"></br>

				<label for='addlsetup'>Additional instructions?</label></br>
				<input type="text" size=50 id="addlsetup" placeholder="additional instructions?"></br>
			</div>
			
		    Turntable RPM: (Different for bond/top? <input id='mrpmcheck' type='checkbox'>)</br>
			<div id='rpms'>
				<input type='text' size=20 class='rpm' id='rpm1' placeholder='RPM'>
				<input type='text' style='display:none' size=20 class='rpm' id='rpm2' placeholder='RPM (top)'>
			</div>
		</div>
		</br>
		
		<div class='sec'>
			<span class='sechead'>Traverse Speeds
					<select id='speedunit'>
						<option value='1'>mm/s</option>
						<option value='.423'>in/min</option>
					</select> 
			</span>
					(Different for bond/top?
                    <input id='mspeedcheck' type='checkbox'>)</br>
                    <div id='speeds'></div>
					</br>
                    <button id="addspeedbtn" type="button">Add Speed</button>
                    <button id="removespeedbtn" type="button">Remove</button>
			
		</div>
		</br>
		
		<div class='sec'>
			<span class='sechead'>Standoffs (in.)</span>
			(Different for bond/top?
			<input id='mstandoff' type='checkbox'>)</br>
			<div id='standoffs' style='display:none'>
				<div style='width:25em'>(Will automatically subtract pointer length from standoff, convert to mm. and apply to tool offset)</div>
				<input type='text' size=13 id='standoff1' placeholder='bond standoff'>
				<input type='text' size=13 id='standoff2' placeholder='top standoff'>
				<input type='text' size=13 id='pointer' placeholder='pointer length'>
			</div>
		</div>
		</br>
		
		<div class='sec'>
			<span class='sechead'>User Options</span>
			<span class='subsechead'>Numerical Options</span>
			<div id="numops"></div></br>
			<button id="addnumoptionbtn" type="button">Add Numerical User Option</button>
			<button id="removenumoptionbtn" type="button">Remove</button>
			</br>
			</br>
			<span class='subsechead'>Multiple Choice Options</span>
			<div id="mcops"></div></br>
			<button id="addmcoptionbtn" type="button">Add Multiple Choice User Option</button>
			<button id="removemcoptionbtn" type="button">Remove</button>
			</br>
		</div>
		</br>
		
		<div class='sec'>
			<span class='sechead'>Robtargets</span>
			<div id='robtargets'></div></br>
			<button id="addrobtargetbtn" type="button">Add Robtargets</button>
			<button id="removerobtargetbtn" type="button">Remove</button></br>
			<button id='showimportrt'>Import robtargets from text...</button></br>
			<div id='importrtc' style='display:none'>
				<textarea id='rtimport' placeholder="paste robtarget lines here to import, e.g. 'CONST robtarget pAPPR:=[.....];... then click import" rows="8" cols="80"></textarea></br>
				<button id="importrtbtn" type="button">Import</button>
			</div>
		</div>
		</br>
		
		<div class='sec' id='roffs'>
			<span class='sechead'>Robot position offsets</span>
			(will be applied to coating moves only)
		</div>
		</br>
		
		<div class='sec'>
			<span class='sechead'>Robot Movements</span>
			<span class='subsechead'>Pre Coating moves:</span>
			<div id='premoves'></div></br>
			<button id="addpremovebtn" type="button">Add Pre Moves</button>
			<button id="removepremovebtn" type="button">Remove</button></br>
			<span class='subsechead'>Coating Moves</span>
			<div id='moves'></div></br>
			<button id="addmovebtn" type="button">Add Moves</button>
			<button id="removemovebtn" type="button">Remove</button></br>
			<span class='subsechead'>Post Coating Moves</span>
			<div id='postmoves'></div></br>
			<button id="addpostmovebtn" type="button">Add post Moves (to top)</button>
			<button id="removepostmovebtn" type="button">Remove (from top)</button>
		</div>
		</br>

        <button id='genp'>Make Program</button>
    </body>
</html>